(function () {
    //左侧导航功能实现
    const navTree = document.querySelector('ul.layui-nav-tree');
    navTree && navTree.addEventListener('click', navTreeFn);

    const headerNavRight = document.querySelector('ul.layui-layout-right');
    headerNavRight && headerNavRight.addEventListener('click', navTreeFn);

    function navTreeFn(event) {
        const target = event.target;
        if (target.tagName.toUpperCase() === 'A' && target.dataset.src) {
            document.querySelector('#main').src = target.dataset.src;
        }
    }

    //获取管理员信息
    axios.get('/api/admin').then(function (res) {
        console.log(res.data);
        if (res.data.code === 1) {
            document.querySelector('.nickname').innerText = res.data.userinfo.adname;
            document.querySelector('img.layui-nav-img').src = res.data.userinfo.avater;
        } else {
            window.location.href = './adminlogin.html';
        }
    }).catch(function (error) {
        console.log(error);
    });


})();